import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shimo_app/pages/components/durationDialog.dart';
import 'package:shimo_app/pages/components/hint.dart';
import 'package:shimo_app/pages/components/loading_button.dart';
import 'package:flutter/services.dart';

import '../components/baseDialog.dart';
import '../components/number_input.dart';
import 'calibration_component_controller.dart';

class CalibrationComponentComponent extends StatelessWidget {
  CalibrationComponentComponent({Key? key}) : super(key: key);

  final controller = Get.put(CalibrationComponentController());
  final state = Get.find<CalibrationComponentController>().state;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.only(left: 20, right: 20),
      child: Wrap(spacing: 20, runSpacing: 20, children: [
        Container(
          width: 390,
          height: 230,
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(20)),
          child: Column(
            children: [
              Text(
                "三轴校准",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text("x轴起点调节预设值"),
                  Text("${controller.xarmHomeCalibrationValue}  mm"),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text("x轴起点调节设置"),
                  NumberInput(
                    onChange: (val) {
                      controller.inputXarmHomeValue = val.toInt();
                      controller.update();
                    },
                  ),
                  LoadingButton(
                      onPressed: () async {
                        if (controller.inputXarmHomeValue < -30 ||
                            controller.inputXarmHomeValue > 30) {
                          showHint("设定失败,请输入-30-30之间的数值", HintType.DANGER);
                          return;
                        }
                        final r = await controller.setXarmHomeCalibrationValue(
                            controller.inputXarmHomeValue);
                        showHint("执行${r ? "成功" : "失败"}",
                            r ? HintType.SUCCESS : HintType.DANGER);
                      },
                      child: Text("设置"))
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text("y轴起点调节预设值"),
                  Text("${controller.yarmHomeCalibrationValue}  mm"),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text("y轴起点调节设置"),
                  NumberInput(
                    onChange: (val) {
                      controller.inputYarmHomeValue = val.toInt();
                      controller.update();
                    },
                  ),
                  LoadingButton(
                      onPressed: () async {
                        if (controller.inputYarmHomeValue < -30 ||
                            controller.inputYarmHomeValue > 30) {
                          showHint("设定失败,请输入-30-30之间的数值", HintType.DANGER);
                          return;
                        }
                        final r = await controller.setYarmHomeCalibrationValue(
                            controller.inputYarmHomeValue);
                        showHint("执行${r ? "成功" : "失败"}",
                            r ? HintType.SUCCESS : HintType.DANGER);
                      },
                      child: Text("设置"))
                ],
              )
            ],
          ),
        ),
        Container(
          width: 390,
          height: 230,
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(20)),
          child:
              GetBuilder<CalibrationComponentController>(builder: (controller) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  "水路校准",
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  height: 20,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("通道"),
                    DropdownButton(
                      value: controller.selectedCalibrationPipeIndex,
                      items: List.generate(
                              controller.valveChannel, (index) => index)
                          .map((e) => DropdownMenuItem<int>(
                                value: e,
                                child: Text("通道${e + 1}"),
                              ))
                          .toList(),
                      onChanged: (int? val) {
                        controller.selectedCalibrationPipeIndex = val!;
                        controller.update();
                      },
                    ),
                    Text(""),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("速度档"),
                    DropdownButton(
                      value: controller.selectedSpeedLevel,
                      items: [
                        DropdownMenuItem<int>(
                          value: 0,
                          child: Text("低速(5ml)"),
                        ),
                        DropdownMenuItem<int>(
                          value: 1,
                          child: Text("高速(10ml)"),
                        ),
                      ],
                      onChanged: (int? val) {
                        controller.selectedSpeedLevel = val!;
                        controller.update();
                      },
                    ),
                    LoadingButton(
                        child: Text("执行"),
                        onPressed: () async {
                          final r = await controller.pumpCalibrationAction();
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                        }),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("标定"),
                    NumberInput(
                      onChange: (val) {
                        controller.actureDosageValue[
                            controller.selectedCalibrationPipeIndex] = val;
                        controller.update();
                      },
                    ),
                    LoadingButton(
                        onPressed: controller.actureDosageValue[
                                    controller.selectedCalibrationPipeIndex] ==
                                0
                            ? null
                            : () async {
                                //获取标定值
                                double num = controller.actureDosageValue[
                                    controller.selectedCalibrationPipeIndex];
                                if (controller.selectedSpeedLevel == 0 &&
                                    (num < 2.5 || num > 7.5)) {
                                  showHint("请输入2.5-7.5之间的值", HintType.DANGER);
                                  return;
                                }
                                if (controller.selectedSpeedLevel == 1 &&
                                    (num < 5 || num > 15)) {
                                  showHint("请输入5-15之间的值", HintType.DANGER);
                                  return;
                                }
                                final result =
                                    await controller.setPumpCalibrationValue(
                                        controller.selectedCalibrationPipeIndex,
                                        controller.selectedSpeedLevel,
                                        controller.actureDosageValue[controller
                                            .selectedCalibrationPipeIndex]);
                                await 300.milliseconds.delay();
                                showHint(
                                    "录入${result ? "成功" : "失败"}",
                                    result
                                        ? HintType.SUCCESS
                                        : HintType.DANGER);
                              },
                        child: Text("录入")),
                  ],
                )
              ],
            );
          }),
        ),
        Container(
          width: 390,
          height: 230,
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(20)),
          child: GetBuilder<CalibrationComponentController>(
            builder: (controller) {
              return Column(
                children: [
                  Text(
                    "清洗参数",
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text("清洗用量"),
                      NumberInput(onChange: (val) {
                        int parsedValue = val.toInt();
                        // if (parsedValue > 60) {
                        //   parsedValue = 60;
                        // }
                        controller.inputChannelCleanDosage = parsedValue;
                        // controller.inputChannelCleanDosage = val.toInt();
                        controller.update();
                      }),
                      LoadingButton(
                          onPressed: controller.inputChannelCleanDosage == 0
                              ? null
                              : () async {
                                  if (controller.inputChannelCleanDosage < 0 ||
                                      controller.inputChannelCleanDosage > 60) {
                                    showHint("请输入0-60之间的值", HintType.DANGER);
                                    return 0;
                                  }
                                  return controller.setChannelCleanDosage(
                                      controller.inputChannelCleanDosage);
                                },
                          child: Text("设定")),
                      Text("${controller.channelCleanDosage}ml(使用中)"),
                    ],
                  ),
                ],
              );
            },
          ),
        ),
        Container(
            width: 390,
            height: 250,
            padding: EdgeInsets.all(20),
            decoration: BoxDecoration(
                color: Colors.black12, borderRadius: BorderRadius.circular(20)),
            child: Column(
              children: [
                Text(
                  "超声校准",
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  height: 5,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("模组1 50ml定容差值"),
                    Row(
                      children: [
                        Text(
                          "${controller.emptyDetectValue} mV",
                          style:
                              TextStyle(decoration: TextDecoration.underline),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "保存数值",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                    ElevatedButton(
                        onPressed: () async {
                          // if (!controller.startGetSensorValueConinues()) {
                          //   showHint("停止中，等待1秒...", HintType.WARNING);
                          //   return;
                          // }
                          showHint("正在执行超声校准", HintType.WARNING);
                          final r =
                              await controller.startGetSensorValueConinues(0);
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                          showBaseDialog(
                            "模组1 支架与50ml液体差值",
                            Size(300, 200),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                SizedBox(
                                  height: 40,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("当前数值"),
                                    GetBuilder<CalibrationComponentController>(
                                        builder: (controller) {
                                      return Text(
                                          "${controller.detectorVal} mV");
                                    }),
                                  ],
                                ),
                                SizedBox(
                                  height: 20,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    LoadingButton(
                                        onPressed: () async {
                                          final r = await controller
                                              .setDistanceSenorCalibration1();
                                          showHint(
                                              "保存${r ? "成功" : "失败"}",
                                              r
                                                  ? HintType.SUCCESS
                                                  : HintType.DANGER);
                                          Navigator.pop(context);
                                          controller.stopGetSensorValue();
                                        },
                                        child: Text("保存"))
                                  ],
                                )
                              ],
                            ),
                            onClose: () {
                              controller.stopGetSensorValue();
                              return true;
                            },
                          );
                        },
                        child: Text("校准"))
                  ],
                ),
                SizedBox(
                  height: 4,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("模组1 25ml定容差值"),
                    Row(
                      children: [
                        Text(
                          "${controller.emptyDetectValue1} mV",
                          style:
                              TextStyle(decoration: TextDecoration.underline),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "保存数值",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                    ElevatedButton(
                        onPressed: () async {
                          // if (!controller.startGetSensorValueConinues()) {
                          //   showHint("停止中，等待1秒...", HintType.WARNING);
                          //   return;
                          // }
                          showHint("正在执行超声校准", HintType.WARNING);
                          final r =
                              await controller.startGetSensorValueConinues(0);
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                          showBaseDialog(
                            "模组1 支架与25ml液体差值",
                            Size(300, 200),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                SizedBox(
                                  height: 40,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("当前数值"),
                                    GetBuilder<CalibrationComponentController>(
                                        builder: (controller) {
                                      return Text(
                                          "${controller.detectorVal} mV");
                                    }),
                                  ],
                                ),
                                SizedBox(
                                  height: 20,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    LoadingButton(
                                        onPressed: () async {
                                          final r = await controller
                                              .setDistanceSenorCalibration2();
                                          showHint(
                                              "保存${r ? "成功" : "失败"}",
                                              r
                                                  ? HintType.SUCCESS
                                                  : HintType.DANGER);
                                          Navigator.pop(context);
                                          controller.stopGetSensorValue();
                                        },
                                        child: Text("保存"))
                                  ],
                                )
                              ],
                            ),
                            onClose: () {
                              controller.stopGetSensorValue();
                              return true;
                            },
                          );
                        },
                        child: Text("校准"))
                  ],
                ),
                SizedBox(
                  height: 4,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("模组2 50ml定容差值"),
                    Row(
                      children: [
                        Text(
                          "${controller.fullDetectValue} mV",
                          style:
                              TextStyle(decoration: TextDecoration.underline),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "保存数值",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                    ElevatedButton(
                        onPressed: () async {
                          // if (!controller.startGetSensorValueConinues()) {
                          //   showHint("停止中，等待1秒...", HintType.WARNING);
                          //   return;
                          // }
                          showHint("正在执行超声校准", HintType.WARNING);
                          final r =
                              await controller.startGetSensorValueConinues(1);
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                          showBaseDialog(
                            "模组2 支架与50ml液体差值",
                            Size(300, 200),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                SizedBox(
                                  height: 40,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("当前数值"),
                                    GetBuilder<CalibrationComponentController>(
                                        builder: (controller) {
                                      return Text(
                                          "${controller.detectorVal} mV");
                                    }),
                                  ],
                                ),
                                SizedBox(
                                  height: 20,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    LoadingButton(
                                        onPressed: () async {
                                          final r = await controller
                                              .setDistanceSenorCalibration3();
                                          showHint(
                                              "保存${r ? "成功" : "失败"}",
                                              r
                                                  ? HintType.SUCCESS
                                                  : HintType.DANGER);
                                          Navigator.pop(context);
                                          controller.stopGetSensorValue();
                                        },
                                        child: Text("保存"))
                                  ],
                                )
                              ],
                            ),
                            onClose: () {
                              controller.stopGetSensorValue();
                              return true;
                            },
                          );
                        },
                        child: Text("校准"))
                  ],
                ),
                SizedBox(
                  height: 4,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("模组2 25ml定容差值"),
                    Row(
                      children: [
                        Text(
                          "${controller.fullDetectValue1} mV",
                          style:
                              TextStyle(decoration: TextDecoration.underline),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "保存数值",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                    ElevatedButton(
                        onPressed: () async {
                          // if (!controller.startGetSensorValueConinues()) {
                          //   showHint("停止中，等待1秒...", HintType.WARNING);
                          //   return;
                          // }
                          showHint("正在执行超声校准", HintType.WARNING);
                          final r =
                              await controller.startGetSensorValueConinues(1);
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                          showBaseDialog(
                            "模组2 支架与25ml液体差值",
                            Size(300, 200),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                SizedBox(
                                  height: 40,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("当前数值"),
                                    GetBuilder<CalibrationComponentController>(
                                        builder: (controller) {
                                      return Text(
                                          "${controller.detectorVal} mV");
                                    }),
                                  ],
                                ),
                                SizedBox(
                                  height: 5,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    LoadingButton(
                                        onPressed: () async {
                                          final r = await controller
                                              .setDistanceSenorCalibration4();
                                          showHint(
                                              "保存${r ? "成功" : "失败"}",
                                              r
                                                  ? HintType.SUCCESS
                                                  : HintType.DANGER);
                                          Navigator.pop(context);
                                          controller.stopGetSensorValue();
                                        },
                                        child: Text("保存"))
                                  ],
                                )
                              ],
                            ),
                            onClose: () {
                              controller.stopGetSensorValue();
                              return true;
                            },
                          );
                        },
                        child: Text("校准"))
                  ],
                ),
                SizedBox(
                  height: 4,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("50ml满管值              "),
                    Row(
                      children: [
                        Text(
                          "${controller.fullDetectValue2} mV",
                          style:
                              TextStyle(decoration: TextDecoration.underline),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "保存数值",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                    ElevatedButton(
                        onPressed: () async {
                          // if (!controller.startGetSensorValueConinues()) {
                          //   showHint("停止中，等待1秒...", HintType.WARNING);
                          //   return;
                          // }
                          showHint("正在执行超声校准", HintType.WARNING);
                          final r =
                              await controller.startGetSensorValueConinues1(0);
                          showHint("执行${r ? "成功" : "失败"}",
                              r ? HintType.SUCCESS : HintType.DANGER);
                          showBaseDialog(
                            "50ml超声值",
                            Size(300, 200),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: [
                                SizedBox(
                                  height: 40,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("当前数值"),
                                    GetBuilder<CalibrationComponentController>(
                                        builder: (controller) {
                                      return Text(
                                          "${controller.detectorVal} mV");
                                    }),
                                  ],
                                ),
                                SizedBox(
                                  height: 20,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    LoadingButton(
                                        onPressed: () async {
                                          final r = await controller
                                              .setDistanceSenorCalibration5();
                                          showHint(
                                              "保存${r ? "成功" : "失败"}",
                                              r
                                                  ? HintType.SUCCESS
                                                  : HintType.DANGER);
                                          Navigator.pop(context);
                                          controller.stopGetSensorValue();
                                        },
                                        child: Text("保存"))
                                  ],
                                )
                              ],
                            ),
                            onClose: () {
                              controller.stopGetSensorValue();
                              return true;
                            },
                          );
                        },
                        child: Text("校准"))
                  ],
                ),
                // SizedBox(
                //   height: 20,
                // ),
                // Row(
                //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //   children: [
                //     Text("自定义"),
                //     Row(
                //       children: [
                //         GetBuilder<CalibrationComponentController>(
                //             builder: (controller) {
                //           return Text(
                //             "${controller.customerDetectValue} mA",
                //             style:
                //                 TextStyle(decoration: TextDecoration.underline),
                //           );
                //         }),
                //         SizedBox(
                //           width: 10,
                //         ),
                //         Text(
                //           "保存数值",
                //           style: TextStyle(color: Colors.grey),
                //         ),
                //       ],
                //     ),
                //     ElevatedButton(
                //         onPressed: () {
                //           if (!controller.startGetSensorValueConinues()) {
                //             showHint("停止中，等待1秒...", HintType.WARNING);
                //             return;
                //           }
                //           showBaseDialog(
                //             "校准自定义超声数值",
                //             Size(300, 140),
                //             Column(
                //               mainAxisAlignment: MainAxisAlignment.spaceAround,
                //               children: [
                //                 SizedBox(
                //                   height: 40,
                //                 ),
                //                 Row(
                //                   mainAxisAlignment:
                //                       MainAxisAlignment.spaceBetween,
                //                   children: [
                //                     Text("当前数值"),
                //                     GetBuilder<CalibrationComponentController>(
                //                         builder: (controller) {
                //                       return Text(
                //                           "${controller.detectorVal} mA");
                //                     }),
                //                   ],
                //                 ),
                //                 SizedBox(
                //                   height: 20,
                //                 ),
                //                 Row(
                //                   mainAxisAlignment: MainAxisAlignment.center,
                //                   children: [
                //                     ElevatedButton(
                //                         onPressed: () async {
                //                           await controller
                //                               .setCustomerSensorCalibration();
                //                           showHint("保存成功", HintType.SUCCESS);
                //                           Navigator.pop(context);
                //                         },
                //                         child: Text("保存"))
                //                   ],
                //                 )
                //               ],
                //             ),
                //             onClose: () {
                //               controller.stopGetSensorValue();
                //               return true;
                //             },
                //           );
                //         },
                //         child: Text("校准"))
                //   ],
                // ),
              ],
            )),
        // Container(
        //   width: 390,
        //   height: 230,
        //   padding: EdgeInsets.all(20),
        //   decoration: BoxDecoration(
        //       color: Colors.black12, borderRadius: BorderRadius.circular(20)),
        //   child:
        //       GetBuilder<CalibrationComponentController>(builder: (controller) {
        //     return Column(
        //       children: [
        //         Text(
        //           "加热参数",
        //           style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
        //         ),
        //         SizedBox(
        //           height: 20,
        //         ),
        //         Row(
        //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //           children: [
        //             Text("Kp"),
        //             NumberInput(onChange: (val) {
        //               controller.Kp = val.toInt();
        //               controller.update();
        //               print("val:${controller.Kp}");
        //             }),
        //             LoadingButton(
        //                 onPressed: controller.Kp == 0
        //                     ? null
        //                     : () async {
        //                         return controller
        //                             .setTargetTemperature(controller.Kp);
        //                       },
        //                 child: Text("设定")),
        //             Text("${controller.Kp}(使用中)"),
        //           ],
        //         ),
        //         SizedBox(
        //           height: 10,
        //         ),
        //         Row(
        //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //           children: [
        //             Text("Ki"),
        //             NumberInput(onChange: (val) {
        //               controller.Ki = val.toInt();
        //               controller.update();
        //             }),
        //             LoadingButton(
        //                 onPressed: controller.Ki == 0
        //                     ? null
        //                     : () async {
        //                         return controller.setAccDuration(controller.Ki);
        //                       },
        //                 child: Text("设定")),
        //             Text("${controller.Ki}(使用中)"),
        //           ],
        //         ),
        //         SizedBox(
        //           height: 10,
        //         ),
        //         Row(
        //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //           children: [
        //             Text("Kd"),
        //             NumberInput(onChange: (val) {
        //               controller.Kd = val.toInt();
        //               controller.update();
        //             }),
        //             LoadingButton(
        //                 onPressed: controller.Kd == 0
        //                     ? null
        //                     : () async {
        //                         return controller
        //                             .setBalanceDuration(controller.Kd);
        //                       },
        //                 child: Text("设定")),
        //             Text("${controller.Kd}(使用中)"),
        //           ],
        //         ),
        //       ],
        //     );
        //   }),
        // ),
        // Container(
        //   width: 390,
        //   height: 230,
        //   padding: EdgeInsets.all(20),
        //   decoration: BoxDecoration(
        //       color: Colors.black12, borderRadius: BorderRadius.circular(20)),
        //   child: GetBuilder<CalibrationComponentController>(
        //     builder: (controller) {
        //       return Column(
        //         children: [
        //           Text(
        //             "清洗参数",
        //             style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
        //           ),
        //           SizedBox(
        //             height: 20,
        //           ),
        //           Row(
        //             mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //             children: [
        //               Text("清洗用量"),
        //               NumberInput(onChange: (val) {
        //                 controller.inputChannelCleanDosage = val.toInt();
        //                 controller.update();
        //               }),
        //               LoadingButton(
        //                   onPressed: controller.inputChannelCleanDosage == 0
        //                       ? null
        //                       : () async {
        //                           return controller.setChannelCleanDosage(
        //                               controller.inputChannelCleanDosage);
        //                         },
        //                   child: Text("设定")),
        //               Text("${controller.channelCleanDosage}ml(使用中)"),
        //             ],
        //           ),
        //         ],
        //       );
        //     },
        //   ),
        // ),
        Container(
          width: 390,
          height: 250,
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(20)),
          child: GetBuilder<CalibrationComponentController>(
            builder: (controller) {
              return Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SizedBox(
                    width: 400,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          "模组1  加热校准",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                        LoadingButton(
                          onPressed: controller.heating
                              ? () async {
                                  await controller.heatOff();
                                }
                              : null,
                          child: Text("停止"),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("0-50℃      "),
                          LoadingButton(
                            onPressed: controller.heating
                                ? null
                                : () async {
                                    return controller
                                        .heatOn(controller.heaterTargets[0]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 65) {
                            //   num = 65;
                            // } else if (num < 35) {
                            //   num = 35;
                            // }
                            controller.inputHeaterCalibrations[0] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations[0] ==
                                        0 ||
                                    controller.heating
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations[0] <
                                            35 ||
                                        controller.inputHeaterCalibrations[0] >
                                            65) {
                                      showHint("设定失败,请输入35-65之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration(0,
                                        controller.inputHeaterCalibrations[0]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("50-110℃  "),
                          LoadingButton(
                            onPressed: controller.heating
                                ? null
                                : () async {
                                    return controller
                                        .heatOn(controller.heaterTargets[1]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 115) {
                            //   num = 115;
                            // } else if (num < 85) {
                            //   num = 85;
                            // }
                            controller.inputHeaterCalibrations[1] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations[1] ==
                                        0 ||
                                    controller.heating
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations[1] <
                                            85 ||
                                        controller.inputHeaterCalibrations[1] >
                                            115) {
                                      showHint("设定失败,请输入85-115之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration(1,
                                        controller.inputHeaterCalibrations[1]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("110-170℃"),
                          LoadingButton(
                            onPressed: controller.heating
                                ? null
                                : () async {
                                    return controller
                                        .heatOn(controller.heaterTargets[2]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 165) {
                            //   num = 165;
                            // } else if (num < 135) {
                            //   num = 135;
                            // }
                            controller.inputHeaterCalibrations[2] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations[2] ==
                                        0 ||
                                    controller.heating
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations[2] <
                                            135 ||
                                        controller.inputHeaterCalibrations[2] >
                                            165) {
                                      showHint("设定失败,请输入135-165之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration(2,
                                        controller.inputHeaterCalibrations[2]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("170-240℃"),
                          LoadingButton(
                            onPressed: controller.heating
                                ? null
                                : () async {
                                    return controller
                                        .heatOn(controller.heaterTargets[3]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 215) {
                            //   num = 215;
                            // } else if (num < 185) {
                            //   num = 185;
                            // }
                            controller.inputHeaterCalibrations[3] =
                                num; // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations[3] ==
                                        0 ||
                                    controller.heating
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations[3] <
                                            185 ||
                                        controller.inputHeaterCalibrations[3] >
                                            215) {
                                      showHint("设定失败,请输入185-215之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration(3,
                                        controller.inputHeaterCalibrations[3]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                ],
              );
            },
          ),
        ),
        Container(
          width: 390,
          height: 250,
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Colors.black12, borderRadius: BorderRadius.circular(20)),
          child: GetBuilder<CalibrationComponentController>(
            builder: (controller) {
              return Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SizedBox(
                    width: 400,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          "模组2  加热校准",
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                        LoadingButton(
                          onPressed: controller.heating1
                              ? () async {
                                  await controller.heatOff1();
                                }
                              : null,
                          child: Text("停止"),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("0-50℃      "),
                          LoadingButton(
                            onPressed: controller.heating1
                                ? null
                                : () async {
                                    return controller
                                        .heatOn1(controller.heaterTargets1[0]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 65) {
                            //   num = 65;
                            // } else if (num < 35) {
                            //   num = 35;
                            // }
                            controller.inputHeaterCalibrations1[0] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations1[0] ==
                                        0 ||
                                    controller.heating1
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations1[0] <
                                            35 ||
                                        controller.inputHeaterCalibrations1[0] >
                                            65) {
                                      showHint("设定失败,请输入35-65之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration1(0,
                                        controller.inputHeaterCalibrations1[0]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("50-110℃  "),
                          LoadingButton(
                            onPressed: controller.heating1
                                ? null
                                : () async {
                                    return controller
                                        .heatOn1(controller.heaterTargets1[1]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 115) {
                            //   num = 115;
                            // } else if (num < 85) {
                            //   num = 85;
                            // }
                            controller.inputHeaterCalibrations1[1] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations1[1] ==
                                        0 ||
                                    controller.heating1
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations1[1] <
                                            85 ||
                                        controller.inputHeaterCalibrations1[1] >
                                            115) {
                                      showHint("设定失败,请输入85-115之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration1(1,
                                        controller.inputHeaterCalibrations1[1]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("110-170℃"),
                          LoadingButton(
                            onPressed: controller.heating1
                                ? null
                                : () async {
                                    return controller
                                        .heatOn1(controller.heaterTargets1[2]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 165) {
                            //   num = 165;
                            // } else if (num < 135) {
                            //   num = 135;
                            // }
                            controller.inputHeaterCalibrations1[2] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations1[2] ==
                                        0 ||
                                    controller.heating1
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations1[2] <
                                            135 ||
                                        controller.inputHeaterCalibrations1[2] >
                                            165) {
                                      showHint("设定失败,请输入135-165之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration1(2,
                                        controller.inputHeaterCalibrations1[2]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("170-240℃"),
                          LoadingButton(
                            onPressed: controller.heating1
                                ? null
                                : () async {
                                    return controller
                                        .heatOn1(controller.heaterTargets1[3]);
                                  },
                            child: Text("执行"),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          NumberInput(onChange: (val) {
                            int num = val.toInt();
                            // if (num > 215) {
                            //   num = 215;
                            // } else if (num < 185) {
                            //   num = 185;
                            // }
                            controller.inputHeaterCalibrations1[3] = num;
                            // (val * 10).toInt();
                            controller.update();
                          }),
                          LoadingButton(
                            onPressed: controller.inputHeaterCalibrations1[3] ==
                                        0 ||
                                    controller.heating1
                                ? null
                                : () async {
                                    if (controller.inputHeaterCalibrations1[3] <
                                            185 ||
                                        controller.inputHeaterCalibrations1[3] >
                                            215) {
                                      showHint("设定失败,请输入185-215之间的数值",
                                          HintType.DANGER);
                                      return;
                                    }
                                    return controller.setHeaterCalibration1(3,
                                        controller.inputHeaterCalibrations1[3]);
                                  },
                            child: Text("设定"),
                          ),
                        ],
                      )
                      // Text("${controller.heaterCalibrations[0]}℃(使用中)"),
                    ],
                  ),
                ],
              );
            },
          ),
        ),
      ]),
    );
  }
}
